package com.nosweattechnet.server;

import java.util.concurrent.ExecutionException;

import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;

public class AddItemListAsyncTask extends CommunicatorAsyncTask {
	private BasicNameValuePair tag=new BasicNameValuePair("tag","addtoItemList");
	private String itemIDString="item_uuid";
	private String userIDString="user_uuid";
	
	//Creates a new Async task and adds the associated values the the name value pairs
	public AddItemListAsyncTask(String item,String user){
		super();
		super.addNameValuePair(tag);
		super.addNameValuePair(new BasicNameValuePair(itemIDString,item));
		super.addNameValuePair(new BasicNameValuePair(userIDString,user));
	}
	
	//Checks if Item was added to the Item List
	public boolean addedFavorite() throws InterruptedException, ExecutionException{
		try {
			JSONArray jarray = this.get();
			if(jarray==null){
				return false;
			}
			if(jarray.getBoolean(0)){
				return true;
			}
		} catch (JSONException e) {
			return false;
		}
		return false;
	}
}
